\(\int (a+b \tan (c+d x))^2 \, dx\) [428]

   Optimal result
   Rubi [A] (verified)
   Mathematica [C] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [A] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [B] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 12, antiderivative size = 39 \[ \int (a+b \tan (c+d x))^2 \, dx=\left (a^2-b^2\right ) x-\frac {2 a b \log (\cos (c+d x))}{d}+\frac {b^2 \tan (c+d x)}{d} \]

[Out]

(a^2-b^2)*x-2*a*b*ln(cos(d*x+c))/d+b^2*tan(d*x+c)/d

Rubi [A] (verified)

Time = 0.02 (sec) , antiderivative size = 39, normalized size of antiderivative = 1.00, number of steps used = 2, number of rules used = 2, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.167, Rules used = {3558, 3556} \[ \int (a+b \tan (c+d x))^2 \, dx=x \left (a^2-b^2\right )-\frac {2 a b \log (\cos (c+d x))}{d}+\frac {b^2 \tan (c+d x)}{d} \]

[In]

Int[(a + b*Tan[c + d*x])^2,x]

[Out]

(a^2 - b^2)*x - (2*a*b*Log[Cos[c + d*x]])/d + (b^2*Tan[c + d*x])/d

Rule 3556

Int[tan[(c_.) + (d_.)*(x_)], x_Symbol] :> Simp[-Log[RemoveContent[Cos[c + d*x], x]]/d, x] /; FreeQ[{c, d}, x]

Rule 3558

Int[((a_) + (b_.)*tan[(c_.) + (d_.)*(x_)])^2, x_Symbol] :> Simp[(a^2 - b^2)*x, x] + (Dist[2*a*b, Int[Tan[c + d
*x], x], x] + Simp[b^2*(Tan[c + d*x]/d), x]) /; FreeQ[{a, b, c, d}, x]

Rubi steps \begin{align*} \text {integral}& = \left (a^2-b^2\right ) x+\frac {b^2 \tan (c+d x)}{d}+(2 a b) \int \tan (c+d x) \, dx \\ & = \left (a^2-b^2\right ) x-\frac {2 a b \log (\cos (c+d x))}{d}+\frac {b^2 \tan (c+d x)}{d} \\ \end{align*}

Mathematica [C] (verified)

Result contains complex when optimal does not.

Time = 0.15 (sec) , antiderivative size = 69, normalized size of antiderivative = 1.77 \[ \int (a+b \tan (c+d x))^2 \, dx=\frac {-i \left ((a+i b)^2 \log (i-\tan (c+d x))-(a-i b)^2 \log (i+\tan (c+d x))\right )+2 b^2 \tan (c+d x)}{2 d} \]

[In]

Integrate[(a + b*Tan[c + d*x])^2,x]

[Out]

((-I)*((a + I*b)^2*Log[I - Tan[c + d*x]] - (a - I*b)^2*Log[I + Tan[c + d*x]]) + 2*b^2*Tan[c + d*x])/(2*d)

Maple [A] (verified)

Time = 0.21 (sec) , antiderivative size = 43, normalized size of antiderivative = 1.10

method result size
norman \(\left (a^{2}-b^{2}\right ) x +\frac {b^{2} \tan \left (d x +c \right )}{d}+\frac {a b \ln \left (1+\tan ^{2}\left (d x +c \right )\right )}{d}\) \(43\)
parallelrisch \(\frac {a^{2} d x -x d \,b^{2}+a b \ln \left (1+\tan ^{2}\left (d x +c \right )\right )+b^{2} \tan \left (d x +c \right )}{d}\) \(43\)
derivativedivides \(\frac {b^{2} \tan \left (d x +c \right )+a b \ln \left (1+\tan ^{2}\left (d x +c \right )\right )+\left (a^{2}-b^{2}\right ) \arctan \left (\tan \left (d x +c \right )\right )}{d}\) \(47\)
default \(\frac {b^{2} \tan \left (d x +c \right )+a b \ln \left (1+\tan ^{2}\left (d x +c \right )\right )+\left (a^{2}-b^{2}\right ) \arctan \left (\tan \left (d x +c \right )\right )}{d}\) \(47\)
parts \(a^{2} x +\frac {b^{2} \left (\tan \left (d x +c \right )-\arctan \left (\tan \left (d x +c \right )\right )\right )}{d}+\frac {a b \ln \left (1+\tan ^{2}\left (d x +c \right )\right )}{d}\) \(47\)
risch \(2 i a b x +a^{2} x -b^{2} x +\frac {4 i a b c}{d}+\frac {2 i b^{2}}{d \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right )}-\frac {2 a b \ln \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right )}{d}\) \(69\)

[In]

int((a+b*tan(d*x+c))^2,x,method=_RETURNVERBOSE)

[Out]

(a^2-b^2)*x+b^2*tan(d*x+c)/d+a*b/d*ln(1+tan(d*x+c)^2)

Fricas [A] (verification not implemented)

none

Time = 0.24 (sec) , antiderivative size = 44, normalized size of antiderivative = 1.13 \[ \int (a+b \tan (c+d x))^2 \, dx=\frac {{\left (a^{2} - b^{2}\right )} d x - a b \log \left (\frac {1}{\tan \left (d x + c\right )^{2} + 1}\right ) + b^{2} \tan \left (d x + c\right )}{d} \]

[In]

integrate((a+b*tan(d*x+c))^2,x, algorithm="fricas")

[Out]

((a^2 - b^2)*d*x - a*b*log(1/(tan(d*x + c)^2 + 1)) + b^2*tan(d*x + c))/d

Sympy [A] (verification not implemented)

Time = 0.08 (sec) , antiderivative size = 48, normalized size of antiderivative = 1.23 \[ \int (a+b \tan (c+d x))^2 \, dx=\begin {cases} a^{2} x + \frac {a b \log {\left (\tan ^{2}{\left (c + d x \right )} + 1 \right )}}{d} - b^{2} x + \frac {b^{2} \tan {\left (c + d x \right )}}{d} & \text {for}\: d \neq 0 \\x \left (a + b \tan {\left (c \right )}\right )^{2} & \text {otherwise} \end {cases} \]

[In]

integrate((a+b*tan(d*x+c))**2,x)

[Out]

Piecewise((a**2*x + a*b*log(tan(c + d*x)**2 + 1)/d - b**2*x + b**2*tan(c + d*x)/d, Ne(d, 0)), (x*(a + b*tan(c)
)**2, True))

Maxima [A] (verification not implemented)

none

Time = 0.33 (sec) , antiderivative size = 41, normalized size of antiderivative = 1.05 \[ \int (a+b \tan (c+d x))^2 \, dx=a^{2} x - \frac {{\left (d x + c - \tan \left (d x + c\right )\right )} b^{2}}{d} + \frac {2 \, a b \log \left (\sec \left (d x + c\right )\right )}{d} \]

[In]

integrate((a+b*tan(d*x+c))^2,x, algorithm="maxima")

[Out]

a^2*x - (d*x + c - tan(d*x + c))*b^2/d + 2*a*b*log(sec(d*x + c))/d

Giac [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 181 vs. \(2 (39) = 78\).

Time = 0.36 (sec) , antiderivative size = 181, normalized size of antiderivative = 4.64 \[ \int (a+b \tan (c+d x))^2 \, dx=\frac {a^{2} d x \tan \left (d x\right ) \tan \left (c\right ) - b^{2} d x \tan \left (d x\right ) \tan \left (c\right ) - a b \log \left (\frac {4 \, {\left (\tan \left (d x\right )^{2} \tan \left (c\right )^{2} - 2 \, \tan \left (d x\right ) \tan \left (c\right ) + 1\right )}}{\tan \left (d x\right )^{2} \tan \left (c\right )^{2} + \tan \left (d x\right )^{2} + \tan \left (c\right )^{2} + 1}\right ) \tan \left (d x\right ) \tan \left (c\right ) - a^{2} d x + b^{2} d x + a b \log \left (\frac {4 \, {\left (\tan \left (d x\right )^{2} \tan \left (c\right )^{2} - 2 \, \tan \left (d x\right ) \tan \left (c\right ) + 1\right )}}{\tan \left (d x\right )^{2} \tan \left (c\right )^{2} + \tan \left (d x\right )^{2} + \tan \left (c\right )^{2} + 1}\right ) - b^{2} \tan \left (d x\right ) - b^{2} \tan \left (c\right )}{d \tan \left (d x\right ) \tan \left (c\right ) - d} \]

[In]

integrate((a+b*tan(d*x+c))^2,x, algorithm="giac")

[Out]

(a^2*d*x*tan(d*x)*tan(c) - b^2*d*x*tan(d*x)*tan(c) - a*b*log(4*(tan(d*x)^2*tan(c)^2 - 2*tan(d*x)*tan(c) + 1)/(
tan(d*x)^2*tan(c)^2 + tan(d*x)^2 + tan(c)^2 + 1))*tan(d*x)*tan(c) - a^2*d*x + b^2*d*x + a*b*log(4*(tan(d*x)^2*
tan(c)^2 - 2*tan(d*x)*tan(c) + 1)/(tan(d*x)^2*tan(c)^2 + tan(d*x)^2 + tan(c)^2 + 1)) - b^2*tan(d*x) - b^2*tan(
c))/(d*tan(d*x)*tan(c) - d)

Mupad [B] (verification not implemented)

Time = 4.67 (sec) , antiderivative size = 136, normalized size of antiderivative = 3.49 \[ \int (a+b \tan (c+d x))^2 \, dx=\frac {a^2\,\mathrm {atan}\left (\frac {a^2\,\mathrm {tan}\left (c+d\,x\right )}{a^2-b^2}-\frac {b^2\,\mathrm {tan}\left (c+d\,x\right )}{a^2-b^2}\right )}{d}-\frac {b^2\,\mathrm {atan}\left (\frac {a^2\,\mathrm {tan}\left (c+d\,x\right )}{a^2-b^2}-\frac {b^2\,\mathrm {tan}\left (c+d\,x\right )}{a^2-b^2}\right )}{d}+\frac {b^2\,\mathrm {tan}\left (c+d\,x\right )}{d}+\frac {a\,b\,\ln \left ({\mathrm {tan}\left (c+d\,x\right )}^2+1\right )}{d} \]

[In]

int((a + b*tan(c + d*x))^2,x)

[Out]

(a^2*atan((a^2*tan(c + d*x))/(a^2 - b^2) - (b^2*tan(c + d*x))/(a^2 - b^2)))/d - (b^2*atan((a^2*tan(c + d*x))/(
a^2 - b^2) - (b^2*tan(c + d*x))/(a^2 - b^2)))/d + (b^2*tan(c + d*x))/d + (a*b*log(tan(c + d*x)^2 + 1))/d